﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net;
using System.IO;

namespace WallPaperU
{
    public partial class MessageEditor : Form
    {
        string sid;
        string did;
        string sinfo;
        public MessageEditor()
        {
            InitializeComponent();
        }
        public MessageEditor(string sids,string dids,string sinfos){
            InitializeComponent();
        sid=sids;
        did=dids;
        sinfo=sinfos;
        label1.Text = sid + ":" + did + ":" + sinfo;
            
        }
        private void MessageEditor_Load(object sender, EventArgs e)
        {
           
        }
        public void SendMsg(List<KeyValuePair<string,string>> list, string url) {
            string postData = "";
            foreach(KeyValuePair<string,string> a in list){
                postData += "&" + a.Key + "=" + a.Value;
            }
            postData = postData.Substring(1);
            byte[] data = System.Text.Encoding.UTF8.GetBytes(postData);
            HttpWebRequest myRequest =
             (HttpWebRequest)WebRequest.Create(url); myRequest.Method = "POST";
            myRequest.ContentType = "application/x-www-form-urlencoded";
            myRequest.ContentLength = data.Length;
            Stream newStream = myRequest.GetRequestStream();  // Send the data.
            newStream.Write(data, 0, data.Length);
            newStream.Close();  // Get response
            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
            string content = reader.ReadToEnd();
            if (content == "OK")
            {
                this.Close();
            }
            else {
                MessageBox.Show(content);
            }

        }

        private void button1_Click(object sender, EventArgs e)
        {
            if(did!="public"){
            List<KeyValuePair<string,string>> list;
            list=new List<KeyValuePair<string,string>>();
            list.Add(new KeyValuePair<string,string>("sid",sid));
            list.Add(new KeyValuePair<string,string>("did",did));
            list.Add(new KeyValuePair<string,string>("info","您的需求："+sinfo+"\r\n"+textBox1.Text));
            SendMsg(list, "http://meik171.duapp.com/Messager?action=ReplySug");//ReplySug
            }else{
            List<KeyValuePair<string,string>> list;
            list=new List<KeyValuePair<string,string>>();
            list.Add(new KeyValuePair<string,string>("did","public"));
            list.Add(new KeyValuePair<string,string>("info",textBox1.Text));
            SendMsg(list,"http://meik171.duapp.com/Messager?action=SendMsg");
            }
   
        }
    }
}
